<?php

namespace App\Models;

use App\Models\Goods;
use App\Models\Server;
use Illuminate\Database\Eloquent\Model;

class Char extends Model
{
    protected $table = 'char';

    public function spells(){
        return $this->hasMany(CharSpell::class,'char_id','id');
    }


    public static function getChar(Server $server,$guid){
        $char=Char::where('server_id',$server->id)
            ->where('character_guid',$guid)
            ->first();
        if(!$char){
            $char=new Char();
            $char->server_id=$server->id;
            $char->character_guid=$guid;
            $char->save();

            $char=Char::find($char->id);
        }
        return $char;
    }
}
